#include <iostream>
#include <conio.h>
#include <stdio.h>
float a[6][6]={{4,3,5,-6,8,-2},{-9,-2,-3,10,4,-3},{2,4,6,-3,-2,2},{5,-7,8,3,9,3},{0,5,-2,10,6,-7},{-10,2,8,5,9,2}};
float k[6][6];
float b[6]={30,50,-32,-24,28,60};
float l[6];
float temp,x[6];
int n,i,j;
void TampilPersamaanK(int i);
void TampilPersamaanA(int i);
void main_2(){
	std::cout<<"==================================================================\n";
	std::cout<<"             PENYELESAIAN SISTEM PERSAMAAN LINIER\n";
	std::cout<<"                        METODE GAUSS\n";
	std::cout<<"==================================================================\n";
	std::cout<<std::endl;

	std::cout<<"Dik. persamaan Liniernya sebagai berikut : \n";
	std::cout<<"==================================================================\n";
	for (i=0;i<6;i++){
		std::cout<<(i+1)<<".) ";
		TampilPersamaanA(i);
	}
	for (n=0;n<(6-1);n++){
		temp = a[n][n];
		//penormalan
		for (j=0;j<6;j++){
			k[n][j]=a[n][j];
			a[n][j]=a[n][j]/temp;
		}
		l[n]=b[n];
		b[n]=b[n]/temp;
		//proses penghilangan variabel
		for (i=(n+1);i<6;i++){
			temp = a[i][n];
			for (j=n;j<6;j++){
				a[i][j]=a[i][j]-(a[n][j]*temp);
			}
			b[i]=b[i]-(b[n]*temp);
		}
	}
	std::cout<<"==================================================================\n";
	std::cout<<"\nSetelah dilakukan penormalan dan penghilangan variabel,\n";
	std::cout<<"maka didapat persamaan baru yaitu \n";
	for (i=0;i<6;i++){
		std::cout<<(i+1)<<".) ";
		if (i<(6-1))
			TampilPersamaanK(i);
		else
			TampilPersamaanA(i);
	}
	//penghitungan x
	temp=a[5][5];
	x[5]=b[5]/temp;
	for (i=(6-2);i>=0;i--){
		temp=k[i][i];
		for (j=i+1;j<6;j++){
			l[i]=l[i]-(k[i][j]*x[j]);
		}
		x[i]=l[i]/temp;
	}
	std::cout<<"\nSetelah dilakukan eliminasi dan substitusi pada persamaan diatas,\n";
	std::cout<<"maka didapat nilai masing-masing x yaitu \n";
	std::cout<<"*********************************\n";
	for (i=0;i<6;i++){
		printf("X%d = %3.4f \n",(i+1),x[i]);
		std::cout<<"=================================\n";
	}
	_getch();
}
void TampilPersamaanA(int i){
	for (j=0;j<6;j++){
		if (j==0){
			std::cout<<(a[i][j])<<"x"<<(j+1)<<" ";
		}else{
			if (a[i][j]<0){
				std::cout<<"- "<<(a[i][j]*-1)<<"x"<<(j+1)<<" ";
			}else if (a[i][j]>=0){
				std::cout<<"+ "<<(a[i][j])<<"x"<<(j+1)<<" ";
			}
		}
	}
	std::cout<<"\t = "<<b[i];
	std::cout<<std::endl;
}
void TampilPersamaanK(int i){
	for (j=0;j<6;j++){
		if (j==0){
			std::cout<<(k[i][j])<<"x"<<(j+1)<<" ";
		}else{
			if (k[i][j]<0){
				std::cout<<"- "<<(k[i][j]*-1)<<"x"<<(j+1)<<" ";
			}else if (k[i][j]>=0){
				std::cout<<"+ "<<(k[i][j])<<"x"<<(j+1)<<" ";
			}
		}
	}
	std::cout<<"\t = "<<l[i];
	std::cout<<std::endl;
}